package de.freudenreichdesign.webshop.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table (name="PERSON")
public class Person implements Serializable {

	private static final long serialVersionUID = 2017542001365391483L;
	private long personID;
	private String title;
	private String gender;
	private String firstName;
	private String lastName;
	private Set<Adress> listOfAdresses = new HashSet<Adress>();
	private String eMail;
	private String phoneNumber;
	
	public Person() {}
	
	public Person(String title, String gender, String firstName,
			String lastName, Adress adress, String eMail,
			String phoneNumber) {
		this.title = title;
		this.gender = gender;
		this.firstName = firstName;
		this.lastName = lastName;
		this.listOfAdresses.add(adress);
		this.eMail = eMail;
		this.phoneNumber = phoneNumber;
	}
	
	@Id
	@GeneratedValue (strategy=GenerationType.AUTO)
	@Column (name="PERSON_ID")
	public long getPersonID() {
		return personID;
	}

	@SuppressWarnings("unused")
	private void setPersonID(long personID) {
		this.personID = personID;
	}

	@Column (name="TITLE")
	public String getTitle() {
		return title;
	}
	
	public void setTitle(String title) {
		this.title = title;
	}
	
	@Column (name="GENDER")
	public String getGender() {
		return gender;
	}
	
	public void setGender(String gender) {
		this.gender = gender;
	}
	
	@Column (name="FIRSTNAME")
	public String getFirstName() {
		return firstName;
	}
	
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	
	@Column (name="LASTNAME")
	public String getLastName() {
		return lastName;
	}
	
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	
	@OneToMany (cascade=CascadeType.ALL ,fetch=FetchType.EAGER)
	@JoinTable(name="ADRESSES_FROM_PERSON",
            joinColumns = @JoinColumn(name="PERSON_ID"),
            inverseJoinColumns = @JoinColumn(name="ADRESS_ID"))
	public Set<Adress> getListOfAdresses() {
		return listOfAdresses;
	}
	
	public void setListOfAdresses(Set<Adress> listOfadress) {
		this.listOfAdresses = listOfadress;
	}
	
	@Column (name="EMAIL")
	public String geteMail() {
		return eMail;
	}
	
	public void seteMail(String eMail) {
		this.eMail = eMail;
	}
	
	@Column (name="PHONE_NUMBER")
	public String getPhoneNumber() {
		return phoneNumber;
	}
	
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}
}
